﻿using MySql.Data.MySqlClient;
using System;
using System.Data;

namespace stuManage
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string loginName= TextBox1.Text.Trim();
            string password = TextBox2.Text.Trim();
            string role = "";
            if (RadioButton1.Checked)
            {
                role= RadioButton1.Text;
            }
            else if(RadioButton2.Checked)
            {
                role = RadioButton2.Text;
            }
            else
            {
                role = RadioButton3.Text;
            }

            string strConn = "server=localhost;port=3306;user id=root;password=lxy1756431734;database=student; pooling=true;";
            MySqlConnection conn = new MySqlConnection(strConn);
            conn.Open();//链接数据库  
            DataSet ds = new DataSet();
            string sql = "select * from login where loginName='{0}' and password='{1}' and role='{2}' ";
            sql = string.Format(sql, loginName, password, role);
            MySqlDataAdapter da = new MySqlDataAdapter(sql, conn);
            da.Fill(ds, "table");
            if (ds.Tables["table"].Rows.Count > 0)
            {
                string s_url = "";
                if (role == "学生")
                {
                    s_url = "stuIndex.aspx?id=" + loginName;

                }
                if (role == "教师")
                {
                    s_url = "teaIndex.aspx?id=" + loginName;

                }
                if (role == "管理员")
                {
                    s_url = "stuInf.aspx";

                }

                Response.Redirect(s_url);
            }
            else
            {
                Response.Write("登录失败");
            }
            conn.Close();


        }
    }
}